package com.chanceit.ssss.popuwindow;

import org.gl.GlobalVariable;
import org.gl.utils.AndroidUtil;
import org.json.JSONObject;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.PopupWindow;
import android.widget.PopupWindow.OnDismissListener;

import com.chanceit.ssss.activity.R;
import com.chanceit.ssss.button.CallPhoneListener;

public class ButtonsPopuWindowForExcepitonDetal extends ButtonsPopuWindow{
	PopupWindow popup;
	Context context;
	int heigh = AndroidUtil.dipToPx(298);
	int weith = AndroidUtil.dipToPx(128);
	public ButtonsPopuWindowForExcepitonDetal(Context c) {
		super(c);
		this.context = c;
	};

	public void showWindow(View parent) {
		if (popup == null) {
			LayoutInflater layoutInflater = (LayoutInflater) context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			View view = layoutInflater.inflate(R.layout.popuwindows_menu_exception, null);
			if (mOnClickListener != null) {
				view.findViewById(R.id.button1).setOnClickListener(
						mOnClickListener);
				view.findViewById(R.id.button2).setOnClickListener(
						mOnClickListener);
				view.findViewById(R.id.button3).setOnClickListener(
						mOnClickListener);
				view.findViewById(R.id.button4).setOnClickListener(
						mOnClickListener);
				view.findViewById(R.id.button5).setOnClickListener(
						mOnClickListener);
				view.findViewById(R.id.button6).setOnClickListener(
						mOnClickListener);
			}

			// 创建一个PopuWidow对象
			popup = new PopupWindow(view,
					weith,
					heigh);
			// 设置焦点在弹窗上
			popup.setFocusable(true);
			// 设置允许在外点击消失
			popup.setOutsideTouchable(true);
			// 设置弹窗消失事件监听
			popup.setOnDismissListener(new OnDismissListener() {
				public void onDismiss() {
					// TODO Auto-generated method stub
					// image.setImageResource(R.drawable.toolbar_plus);
				}
			});
			// 这个是为了点击“返回Back”也能使其消失，并且并不会影响你的背景
//			new AndroidDrawableUtil().drawLayoutDropShadow(view,weith+10,heigh);
			popup.setBackgroundDrawable(new ColorDrawable(0x00000000));
			popup.setTouchInterceptor(new OnTouchListener() {
				public boolean onTouch(View view, MotionEvent event) {
					if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
						popup.dismiss();
						// image.setImageResource(R.drawable.toolbar_plus);
						return true;
					}
					return false;
				}
			});
		}
		if (!popup.isShowing()) {
			popup.showAsDropDown(parent, GlobalVariable.disPlay_w-AndroidUtil.dipToPx(142), 0);
		}
	}

	public void showWindow(View parent, JSONObject selectCarerInfo) {
		View view = getView(R.layout.popuwindows_menu_exception, selectCarerInfo);
		if (mOnClickListener != null) {
			view.findViewById(R.id.button6).setOnClickListener(
					mOnClickListener);
		}
		// 创建一个PopuWidow对象
		popup = new PopupWindow(view, weith, heigh);
		// 设置焦点在弹窗上
		popup.setFocusable(true);
		// 设置允许在外点击消失
		popup.setOutsideTouchable(true);
		// 设置弹窗消失事件监听
		popup.setOnDismissListener(new OnDismissListener() {
			public void onDismiss() {
				// image.setImageResource(R.drawable.toolbar_plus);
			}
		});
		// 这个是为了点击“返回Back”也能使其消失，并且并不会影响你的背景
		// new
		// AndroidDrawableUtil().drawLayoutDropShadow(view,AndroidUtil.dipToPx(135),AndroidUtil.dipToPx(298));
		popup.setBackgroundDrawable(new ColorDrawable(0x00000000));
		popup.setTouchInterceptor(new OnTouchListener() {
			public boolean onTouch(View view, MotionEvent event) {
				if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
					popup.dismiss();
					// image.setImageResource(R.drawable.toolbar_plus);
					return true;
				}
				return false;
			}
		});
		if (!popup.isShowing()) {
			popup.showAsDropDown(parent,
					GlobalVariable.disPlay_w - AndroidUtil.dipToPx(142), 0);
		}

	}
}
